Skip to content

Method: DefaultUserAction(Callback, Collection)

1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.role.ui.impl;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Collection;
31: import it.tidalwave.util.As;
32: import it.tidalwave.util.Callback;
33: import it.tidalwave.role.ui.BoundProperty;
34: import it.tidalwave.role.ui.UserAction;
35: import lombok.Getter;
36: import lombok.RequiredArgsConstructor;
37: import lombok.experimental.Accessors;
38: import lombok.experimental.Delegate;
39: import lombok.extern.slf4j.Slf4j;
40:
41: /***********************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: @RequiredArgsConstructor(staticName = "withCallback") @Slf4j
47: public class DefaultUserAction implements UserAction
48: {
49: @Getter @Accessors(fluent = true)
50: private final BoundProperty<Boolean> enabled = new BoundProperty<>(true);
51:
52: @Delegate @Nonnull
53: private final As as;
54:
55: @Nonnull
56: private final Callback callback;
57:
58: /*******************************************************************************************************************
59: *
60: * @since 3.2-ALPHA-1 (was previously in {@code UserAction8}
61: * @since 3.2-ALPHA-3 (refactored)
62: *
63: ******************************************************************************************************************/
64: public DefaultUserAction (@Nonnull final Callback callback, @Nonnull final Collection<Object> roles)
65: {
66: this.callback = callback;
67: this.as = As.forObject(this, roles);
68: }
69:
70: /*******************************************************************************************************************
71: *
72: * @since 3.2-ALPHA-1 (was previously in {@code UserAction8}
73: * @since 3.2-ALPHA-3 (refactored)
74: *
75: ******************************************************************************************************************/
76: @Nonnull
77: public DefaultUserAction withRoles (@Nonnull final Collection<Object> roles)
78: {
79: return new DefaultUserAction(callback, roles);
80: }
81:
82: @Override
83: public void actionPerformed() // FIXME: change with composition
84: {
85: try
86: {
87: callback.call();
88: }
89: catch (Throwable e)
90: {
91: log.error("", e);
92: }
93: }
94: }